package hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.exceptions.DeserializationException;

public class TableTest {

	public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException, DeserializationException {
		
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", "master");
		
		HBaseAdmin admin = new HBaseAdmin(conf);
		try {
			//创建表
			@SuppressWarnings("deprecation")
			HTableDescriptor table = new HTableDescriptor("user");
			table.addFamily(new HColumnDescriptor("teacher"));
			table.addFamily(new HColumnDescriptor("hobby"));
			admin.createTable(table);
			
			//修改表
//			admin.disableTable("user");
//			admin.modifyColumn("user", new HColumnDescriptor("username"));
//			admin.enableTable("user");
			
			//删除表
//			admin.disableTable("user");
//			admin.deleteTable("user");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			admin.close();
		}
	}
}
